Skip to content

Conversation

@braia123
Copy link
Collaborator

@braia123 braia123 commented Oct 26, 2025

Link issues

fixes #7010

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Persist and restore BootstrapBlazor table column visibility settings using browser localStorage keyed by ClientTableName and refactor related methods to async to support storage operations

New Features:

  • Persist table column visibility preferences in browser localStorage per ClientTableName

Enhancements:

  • Make column visibility reset and dynamic context reset methods async to support JSRuntime storage operations
  • Save updated visibility settings to localStorage when toggling column visibility

Documentation:

  • Add ClientTableName attribute to sample table to demonstrate column visibility persistence

@bb-auto
Copy link

bb-auto bot commented Oct 26, 2025

Thanks for your PR, @braia123. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 26, 2025

Reviewer's Guide

This PR adds per-table persistence of column visibility by converting internal visibility reset methods to async, reading and writing visibility states to localStorage keyed by ClientTableName, and updating related method calls and samples accordingly.

Sequence diagram for persisting column visibility to localStorage

sequenceDiagram
    participant TableComponent
    participant JSRuntime
    participant localStorage
    TableComponent->>JSRuntime: InvokeVoidAsync("localStorage.setItem", key, value)
    JSRuntime->>localStorage: setItem(key, value)
    localStorage-->>JSRuntime: (stores value)
    JSRuntime-->>TableComponent: (async complete)
Loading

Sequence diagram for restoring column visibility from localStorage

sequenceDiagram
    participant TableComponent
    participant JSRuntime
    participant localStorage
    TableComponent->>JSRuntime: InvokeAsync("localStorage.getItem", key)
    JSRuntime->>localStorage: getItem(key)
    localStorage-->>JSRuntime: value
    JSRuntime-->>TableComponent: value
    TableComponent->>TableComponent: Deserialize value
    TableComponent->>TableComponent: Apply visibility to columns
Loading

Entity relationship diagram for persisted column visibility data

erDiagram
    TABLE {
        string ClientTableName
        bool ShowColumnList
    }
    COLUMN_VISIBLE_ITEM {
        string Name
        bool Visible
        string DisplayName
    }
    TABLE ||--o{ COLUMN_VISIBLE_ITEM : has
    LOCAL_STORAGE {
        string key
        string value_JSON
    }
    TABLE ||--o{ LOCAL_STORAGE : persists visibility
Loading

Class diagram for updated Table component column visibility logic

classDiagram
    class Table {
        +ClientTableName : string
        +ShowColumnList : bool
        +Columns : List<ITableColumn>
        +_visibleColumns : List<ColumnVisibleItem>
        +ResetVisibleColumns(columns)
        +InternalResetVisibleColumns(columns, items)
        +OnToggleColumnVisible(columnName, visible)
    }
    class ColumnVisibleItem {
        +Name : string
        +Visible : bool
        +DisplayName : string
    }
    Table o-- "*" ColumnVisibleItem : manages
    Table --> JSRuntime : uses
    JSRuntime --> localStorage : interacts
    Table --> ColumnVisibleItem : serializes/deserializes
Loading

File-Level Changes

Change Details Files
InternalResetVisibleColumns made asynchronous with localStorage read integration
  • Changed InternalResetVisibleColumns signature to async Task and awaited its calls in ProcessFirstRender
  • Used JSRuntime.InvokeAsync to retrieve stored visibility JSON by key
  • Deserialized JSON into ColumnVisibleItem list and merged persisted visibility into current columns
Table.razor.cs
ResetVisibleColumns and ResetDynamicContext refactored to async
  • Updated ResetVisibleColumns signature to async Task and awaited InternalResetVisibleColumns
  • Changed ResetDynamicContext to async Task
  • Awaited ResetDynamicContext calls in AddAsync, DeleteAsync, and DeleteItemsAsync
Table.razor.cs
Table.razor.Toolbar.cs
Persist visibility toggles to localStorage
  • Imported System.Text.Json
  • Added JSRuntime.InvokeVoidAsync call in OnToggleColumnVisible to serialize and store current _visibleColumns
Table.razor.Checkbox.cs
Sample updated to specify ClientTableName for demo persistence
  • Added ClientTableName="testtable" to Table component in sample
TablesColumnList.razor

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot requested a review from ArgoZhang October 26, 2025 14:44
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Oct 26, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • There's a typo in the localStorage key ("bb-table-column-visiable-…")—consider renaming it to use the correct spelling ("visible") to avoid confusion.
  • You changed several public methods (ResetVisibleColumns, InternalResetVisibleColumns, ResetDynamicContext) from void to async Task; this is a breaking API change—consider preserving backward‐compatible overloads or clearly documenting the version bump.
  • The catch around JsonSerializer.Deserialize swallows all errors silently; you should at least log the exception or handle specific failure cases to aid debugging.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- There's a typo in the localStorage key ("bb-table-column-visiable-…")—consider renaming it to use the correct spelling ("visible") to avoid confusion.
- You changed several public methods (ResetVisibleColumns, InternalResetVisibleColumns, ResetDynamicContext) from void to async Task; this is a breaking API change—consider preserving backward‐compatible overloads or clearly documenting the version bump.
- The catch around JsonSerializer.Deserialize swallows all errors silently; you should at least log the exception or handle specific failure cases to aid debugging.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Table/Table.razor.cs:1261` </location>
<code_context>
     }

-    private void InternalResetVisibleColumns(List<ITableColumn> columns, IEnumerable<ColumnVisibleItem>? items = null)
+    private async Task InternalResetVisibleColumns(List<ITableColumn> columns, IEnumerable<ColumnVisibleItem>? items = null)
     {
         var cols = columns.Select(i => new ColumnVisibleItem(i.GetFieldName(), i.GetVisible()) { DisplayName = i.GetDisplayName() }).ToList();
</code_context>

<issue_to_address>
**suggestion:** Consider handling deserialization exceptions explicitly for better error tracking.

Leaving the catch block empty can hide deserialization errors. Consider logging or reporting exceptions to aid debugging.
</issue_to_address>

### Comment 2
<location> `src/BootstrapBlazor/Components/Table/Table.razor.Checkbox.cs:162` </location>
<code_context>
 // See the LICENSE file in the project root for more information.
 // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

+using System.Text.Json;
+
 namespace BootstrapBlazor.Components;
</code_context>

<issue_to_address>
**suggestion:** Check for consistency in serialization options between saving and loading column visibility.

Serialization should use _serializerOption to ensure compatibility with deserialization and prevent potential mismatches.

```suggestion
            await JSRuntime.InvokeVoidAsync("localStorage.setItem", "bb-table-column-visiable-"+ClientTableName, JsonSerializer.Serialize(_visibleColumns, _serializerOption) ?? "");
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (854643e) to head (d7318c1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7011   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          742       743    +1     
  Lines        32398     32451   +53     
  Branches      4485      4495   +10     
=========================================
+ Hits         32398     32451   +53     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bb-auto bb-auto bot added the enhancement New feature or request label Oct 27, 2025
@bb-auto bb-auto bot added this to the 9.11.0 milestone Oct 27, 2025
ArgoZhang
ArgoZhang previously approved these changes Oct 27, 2025
@ArgoZhang ArgoZhang changed the title 持久化列的显隐到bb-table-column-visiable-{ClientTableName} feat(Table): add ReloadColumnVisibleFromBrowserAsync method Oct 27, 2025
@ArgoZhang ArgoZhang merged commit c29d23a into main Oct 27, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the Table-ShowColumnList branch October 27, 2025 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Table): ShowColumnList的内容希望进行本地化存储

3 participants